package com.cunshe.web.manage;

import com.cunshe.common.ResponseVO;
import com.cunshe.config.annotation.Login;
import com.cunshe.dao.CooperativeCustomersDao;
import com.cunshe.domain.CooperativeCustomers;
import com.cunshe.entity.vo.CooperativeCustomersInsertVO;
import com.cunshe.entity.vo.CooperativeCustomersUpdateVO;
import com.cunshe.service.CooperativeCustomersService;
import com.cunshe.web.BaseController;
import com.sunkee.commons.utils.ConvertUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 合作客户
 * @author xiao
 */
@Api(tags = "合作客户")
@Login
@RestController
@RequestMapping("/manage/cooperativeCustomers")
public class CooperativeCustomersController extends BaseController {

    @Autowired
    private CooperativeCustomersService cooperativeCustomersService;

    /** 新增 */
    @ApiOperation(value = "新增")
    @PostMapping(value = "insert")
    public ResponseVO insert(@RequestBody @Validated CooperativeCustomersInsertVO vo) {
        CooperativeCustomers record = ConvertUtil.copyProperties(vo, CooperativeCustomers.class);
        record.setCreateBy(getCurrentUser().getUsername());
        cooperativeCustomersService.insert(record);
        return ResponseVO.success();
    }

    /** 删除 */
    @ApiOperation(value = "删除")
    @PostMapping(value = "delete")
    public ResponseVO delete(@RequestParam("id") Long id) {
        int delete = cooperativeCustomersService.delete(id);
        return ResponseVO.success();
    }

    /** 修改 */
    @ApiOperation(value = "修改")
    @PostMapping(value = "update")
    public ResponseVO update(@RequestBody @Validated CooperativeCustomersUpdateVO vo) {
        CooperativeCustomers record = ConvertUtil.copyProperties(vo, CooperativeCustomers.class);
        record.setUpdateBy(getCurrentUser().getUsername());
        cooperativeCustomersService.update(record);
        return ResponseVO.success();
    }

    /** 查询列表 */
    @ApiOperation(value = "查询列表")
    @PostMapping(value = "list")
    public ResponseVO list(CooperativeCustomers record) {
        List<CooperativeCustomers> list = cooperativeCustomersService.list(record);
        return ResponseVO.success(list);
    }

}